package cn.com.utt.common.util;

import com.alibaba.fastjson.JSONObject;
import cn.com.utt.common.http.Client;

public class WxApi {

	private static String authorizertoken_api = "http://localhost:28080/open/weixin/authorizeraccesstoken";

	public static JSONObject authorizerAccessToken(long cfgId, String authorizerAppId) {
		String url = authorizertoken_api + "/" + cfgId + "/" + authorizerAppId;
		System.out.println(url);
		Client client = new Client();
		String result = client.doPostWithJson(url, "");
		JSONObject json = (JSONObject) JSONObject.parse(result);
		System.out.println(json);
		return json;
	}

	public static JSONObject getShopList(String accessToken, int pageIndex, int pageSize) {
		String url = "https://api.weixin.qq.com/bizwifi/shop/list?access_token=" + accessToken;
		String data = "{\"pageindex\":" + pageIndex + ",\"pagesize\":" + pageSize + "}";
		System.out.println(url);
		System.out.println(data);
		Client client = new Client();
		String result = client.doPostWithJson(url, data);
		JSONObject json = (JSONObject) JSONObject.parse(result);
		System.out.println(json);
		return json;
	}

	public static JSONObject getShopSecret(String accessToken, String ssid, long shopId) {
		String url = "https://api.weixin.qq.com/bizwifi/apportal/register?access_token=" + accessToken;
		String data = "{\"shop_id\":" + shopId + ",\"ssid\":\"" + ssid + "\",\"reset\":false}";
		System.out.println(url);
		System.out.println(data);
		Client client = new Client();
		String result = client.doPostWithJson(url, data);
		JSONObject json = (JSONObject) JSONObject.parse(result);
		return json;
	}

	public static JSONObject setFinishPage(String accessToken, String finishpage, long shopId) {
		String url = "https://api.weixin.qq.com/bizwifi/finishpage/set?access_token=" + accessToken;
		String data = "{\"shop_id\":" + shopId + ",\"finishpage_url\":\"" + finishpage + "\"}";
		System.out.println(url);
		System.out.println(data);
		Client client = new Client();
		String result = client.doPostWithJson(url, data);
		JSONObject json = (JSONObject) JSONObject.parse(result);
		return json;
	}

}
